package com.taotao.thread.Test1;

import ch.qos.logback.core.pattern.FormatInfo;
import sun.applet.Main;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author wangjin
 * @title: T01_AtomicInteger
 * @projectName thread
 * @description: AtomicInteger
 * @date 2022/5/4 0004 8:35
 */
public class T01_AtomicInteger {
    AtomicInteger counter=new AtomicInteger(0);
    void m(){
        for (int i = 0; i <10000 ; i++) {
            counter.incrementAndGet();
        }
    }
    public static void main(String[] args) {
        T01_AtomicInteger t01_atomicInteger = new T01_AtomicInteger();
        List<Thread> list=new ArrayList<>();
        for (int i = 0; i <10 ; i++) {
            list.add(new Thread(t01_atomicInteger::m,"thread-"+i));

        }
        list.forEach((o)->{
            o.start();
        });
        list.forEach((o)->{
            try {
                o.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        System.out.println(t01_atomicInteger.counter);
    }
}
